package DataStructure.iterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorListTest {
    public static void main(String[] args) {
        //实例化ArrayList容器
        List<String> list = new ArrayList<>();

        list.add("a");
        list.add("b");
        list.add("c");

        //方式一：在迭代器中通过while获取元素
        //获取迭代器对象
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

        //方式二：在迭代器中通过for循环获取元素
        for(Iterator<String> it2 = list.iterator();it2.hasNext();){
            System.out.println(it2.next());
        }
    }
}
